Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: delayed hydration #26468

Open
wants to merge 150 commits into
base: main
Choose a base branch
from
Open

Conversation

GalacticHypernova
Copy link
Contributor

@GalacticHypernova GalacticHypernova commented Mar 24, 2024

πŸ”— Linked issue

#24242

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Lazy loading is a very beneficial addition to the nuxt core. Natively supporting delayed hydration will provide significant performance improvement. Moreover, it will reduce the amount of boilerplate code needed for manual implementations, and will reduce bundle size by not requiring external modules for something that may very well be handled out-of-the-box, as part of the Lazy components behavior.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have added tests (if possible).
  • I have updated the documentation accordingly.

TODO (optional):

  • Infer/retrieve the dimensions of the original component or provide a sensible default to allow for an empty div with the inferred dimensions, thus reducing the SSR payload while still preventing CLS
  • Add more types of delayed hydration (not necessary, as other types are likely highly personal and depend on per-developer implementation)

Copy link

stackblitz bot commented Mar 24, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@GalacticHypernova GalacticHypernova marked this pull request as ready for review June 10, 2024 16:58
@danielroe
Copy link
Member

πŸŽ‰

@GalacticHypernova GalacticHypernova changed the title feat: lazy hydration feat: delayed hydration Jun 10, 2024
idleHandle = null
}
})
return () => h('div', {}, [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a div here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not, I was thinking about it here, I'll remove it
Now that I think about it, do we need the div in the visibility based component in the import.meta.server check?

@GalacticHypernova
Copy link
Contributor Author

I was thinking of changing up the way visibility based component behaves, to ensure we don't pollute the DOM unnecessarily with extra nodes. What do you think? Do note I wrote this on my phone right in this message so it may have some mistakes, but I'm talking about the general idea.

return () => {
  if (!isIntersecting.value && (!instance.vnode.el || !nuxt.isHydrating)) {
    return h('div', { ref: el });
  }
  if (isIntersecting.value) {
    return h(componentLoader, attrs);
  } else {
    const fragmentHTML = getFragmentHTML(instance.vnode.el ?? null, true)?.join('') || '';
    return createVNode(createStaticVNode(fragmentHTML, 1));
  }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants